package com.dcivision.dms.web;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.dcivision.framework.GlobalConstant;
import com.dcivision.framework.SystemFunctionConstant;
import com.dcivision.framework.Utility;

public class MaintWorkflowRoutineAction extends com.dcivision.dms.web.MaintDmsDocumentAction implements com.dcivision.framework.web.WorkflowActionInterface {

  public MaintWorkflowRoutineAction() {
    super();
  }

  /**
   * getMajorDAOClassName
   *
   * @return  The class name of the major DAObject will be used in this action.
   */
  public String getMajorDAOClassName() {
    return("com.dcivision.dms.dao.DmsDocumentDAObject");
  }

  /**
   * getFunctionCode
   *
   * @return  The corresponding system function code of action.
   */
  public String getFunctionCode() {
    return(SystemFunctionConstant.DMS_PERSONAL_FOLDER);
  }
  
  public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException {
    String rootID= request.getParameter("rootID");
    MaintDmsDocumentForm maintForm = (MaintDmsDocumentForm)form;
    maintForm.setRootID(rootID);
//  Set function code if necessary.
    if (!Utility.isEmpty(maintForm.getCurFunctionCode())) {
      this.setFunctionCode(maintForm.getCurFunctionCode());
    }else if(!Utility.isEmpty(request.getParameter("sCurFunctionCode"))){
      this.setFunctionCode(request.getParameter("sCurFunctionCode"));
    }     

    ActionForward forward = this.retrieveFunctionCode(request, response, mapping);
    if (forward!=null) {
      return forward;
    }
    return mapping.findForward(GlobalConstant.NAV_MODE_EDIT);
    //return super.execute(mapping,form,request,response);
  }
  
}
